package edu.tyut.game.utils

import android.app.Activity
import android.os.Build
import android.view.View
import android.view.WindowInsets
import android.view.WindowInsetsController
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import edu.tyut.game.MainActivity

object StatusBarUtils {
    /**
     * 设置状态栏透明
     */
    fun setTranslucentStatusBar(activity: AppCompatActivity){
        // 隐藏ActionBar
        activity.supportActionBar?.hide()
        // 状态栏透明
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            val window = activity.window

            // 是这段代码导致的EditText无法再软键盘之上
            window.setDecorFitsSystemWindows(false)
            window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)

            val controller = window.insetsController
            controller?.apply {
                // 隐藏导航栏菜单栏
                // hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
                setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS)
                show(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
            }
        }
        // ==========
    }
}